﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Matopeli
{
    public class Omena : INotifyPropertyChanged
    {
        #region Constructors
        
        public Omena() { }
        public Omena(double x, double y)
        {
            X = x;
            Y = y;
            Size = 20;

            Syoty = false;
        }

        #endregion

        #region Properties

        double x;
        public double X
        {
            get { return x; }
            set
            {
                SetField(ref x, value, "X");
                NotifyChange("ActualX");
            }
        }

        double y;
        public double Y
        {
            get { return y; }
            set
            {
                SetField(ref y, value, "Y");
                NotifyChange("ActualY");
            }
        }

        double size;
        public double Size
        {
            get { return size; }
            set
            {
                SetField(ref size, value, "Size");
                NotifyChange("ActualX");
                NotifyChange("ActualY");
            }
        }

        public double ActualX
        {
            get { return X - Size / 2.0; }
        }

        public double ActualY
        {
            get { return Y - Size / 2.0; }
        }

        public bool Syoty { get; set; }
        
        #endregion

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        public void SetField<T>(ref T field, T value, string propertyName)
        {
            if (EqualityComparer<T>.Default.Equals(field, value))
                return;

            field = value;

            NotifyChange(propertyName);
        }

        public void NotifyChange(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion
    }
}
